home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / system / 4utils84.zip / globals.pas < prev    next >
Pascal/Delphi Source File  |  1994-10-08  |  6KB  |  208 lines

  1. UNIT Globals;
  2. (* ----------------------------------------------------------------------
  3.    Part of 4FF   - 4DOS File Finder
  4.  
  5.    (c) 1992, 1993 Copyright by David Frey,
  6.                                Urdorferstrasse 30
  7.                                8952 Schlieren ZH
  8.                                Switzerland
  9.  
  10.    DISCLAIMER: This unit is freeware: you are allowed to use, copy
  11.                and change it free of charge, but you may not sell or hire
  12.                this part of 4DESC. The copyright remains in our hands.
  13.  
  14.                If you make any (considerable) changes to the source code,
  15.                please let us know. (send a copy or a listing).
  16.                We would like to see what you have done.
  17.  
  18.                We, David Frey and Tom Bowden, the authors, provide absolutely
  19.                no warranty of any kind. The user of this software takes the
  20.                entire risk of damages, failures, data losses or other
  21.                incidents.
  22.  
  23.  
  24.        Code created using Turbo Pascal 7.0 (c) Borland International 1992
  25.  
  26.    This unit provides the string handling and the date/time handling.
  27.  
  28.    ----------------------------------------------------------------------- *)
  29.  
  30. INTERFACE USES Objects, Dos, StringDateHandling;
  31.  
  32. CONST MaxFileSpecs      =   6;
  33.       DescLen           = 200;
  34.  
  35. TYPE  DescStr           = STRING[DescLen];
  36.       NameExtStr        = STRING[8+1+3];
  37.       FileSpecArrayType = ARRAY[1..MaxFileSpecs] OF NameExtStr;
  38.  
  39. (* command line flags: *)
  40.  
  41. VAR   ExactAttr                : BOOLEAN;
  42.       ScanLZHArchives          : BOOLEAN;
  43.       ScanZIPArchives          : BOOLEAN;
  44.       ScanARJArchives          : BOOLEAN;
  45.       SubDirectories, AllDrives: BOOLEAN;
  46.       BareOutput               : BOOLEAN;
  47.       DoPage                   : BOOLEAN;
  48.       Drive                    : CHAR;
  49.       searchdesc               : DescStr;
  50.  
  51. (* Global variables *)
  52.  
  53. VAR   Attr                     : BYTE;
  54.       DirSize,   TotalSize     : LONGINT;
  55.       FileCount, TotalFileCount: WORD;
  56.  
  57. VAR   FileName                 : NameExtStr;
  58.       Search                   : SearchRec;
  59.       Path                     : PathStr;
  60.       Name                     : NameStr;
  61.       Dir                      : DirStr;
  62.       Ext                      : ExtStr;
  63.  
  64. VAR   f                        : FILE; (* the archive *)
  65.  
  66. VAR   InfoArray                : ARRAY[0..6] OF PString;
  67.       AttrStr, FileStr, SizeStr: STRING;
  68.       Date                     : DateStr;
  69.       Time                     : TimeStr;
  70.       DateRec                  : DateTime;
  71.  
  72. VAR   csize                    : LONGINT;    (* compressed size *)
  73.       fstamp                   : DateTime;   (* last mod file date/time (turbo format) *)
  74.       s                        : STRING;
  75.  
  76. (* Templates for FormatStr *)
  77.  
  78. VAR   DateTempl : STRING[4];
  79.       TimeTempl : STRING[4];
  80.       DescTempl : STRING[5];
  81.  
  82. VAR   MaxViewLength : BYTE;
  83.  
  84. (* Buffer related variables: *)
  85.  
  86. CONST MaxBufSize = 65500;
  87.  
  88. TYPE  PBuffer = ^TBuffer;
  89.       TBuffer = ARRAY[0..MaxBufSize] OF BYTE;
  90.  
  91. VAR   BufPtr    : LONGINT;
  92.       BytesRead : WORD;
  93.       BufSize   : WORD;
  94.       FilePtr   : LONGINT;
  95.  
  96. VAR   Buffer    : PBuffer;
  97.  
  98. VAR   Line      : BYTE;
  99.       Redirected: BOOLEAN;
  100.  
  101. PROCEDURE TestForMoreMsg;
  102.  
  103. PROCEDURE InstallBuffer;
  104. PROCEDURE FreeBuffer;
  105. FUNCTION  ReadByte: BYTE;
  106.  
  107. IMPLEMENTATION USES Memory, Crt,
  108.                     HandleINIFile, DescriptionHandling;
  109.  
  110. VAR   ScreenHeight : BYTE;
  111.       HilightMore  : BOOLEAN;
  112.  
  113. FUNCTION TestIfRedirected: BOOLEAN;
  114.  
  115. TYPE TPSP = ARRAY[0..$FF] OF BYTE;
  116.  
  117. VAR  PSP  : ^TPSP;
  118.  
  119. BEGIN
  120.  PSP := Ptr(PrefixSeg,0);
  121.  TestIfRedirected := (PSP^[$19] <> 1);
  122. END;
  123.  
  124. PROCEDURE TestForMoreMsg;
  125.  
  126. VAR ch: CHAR;
  127.  
  128. BEGIN
  129.  INC(Line);
  130.  IF KeyPressed OR (Line = ScreenHeight) THEN
  131.   BEGIN
  132.    IF KeyPressed THEN ch := ReadKey;
  133.    HighVideo; Write('-- more --',#13); LowVideo;
  134.    REPEAT UNTIL KeyPressed;
  135.    ch := ReadKey;
  136.    ClrEOL;
  137.    IF Line = ScreenHeight THEN Line := 1;
  138.   END;
  139. END;
  140.  
  141. PROCEDURE InstallBuffer;
  142.  
  143. BEGIN
  144.  IF MaxAvail < MaxBufSize THEN BufSize:= WORD(MaxAvail)
  145.                           ELSE BufSize:= MaxBufSize;
  146.  
  147.  GetMem(Buffer,BufSize);
  148.  IF Buffer = NIL THEN
  149.   BEGIN
  150.    WriteLn(Output);
  151.    WriteLn(Output,'Fatal Error : Unable to allocate Buffer!');
  152.    HALT(255);
  153.   END;
  154. END; (* InstallBuffer *)
  155.  
  156. PROCEDURE FreeBuffer;
  157.  
  158. BEGIN
  159.  FreeMem(Buffer,BufSize);
  160. END; (* FreeBuffer *)
  161.  
  162. FUNCTION ReadByte: BYTE;
  163.  
  164. BEGIN
  165.  IF BufPtr >= BufSize THEN
  166.   BEGIN
  167.    BlockRead(f,Buffer^,BufSize, BytesRead);
  168.    BufPtr := 0;
  169.   END;
  170.  
  171.  ReadByte := Buffer^[BufPtr]; INC(BufPtr); INC(FilePtr);
  172. END; (* ReadByte *)
  173.  
  174. BEGIN
  175.  Str(Length(DateFormat),DateTempl); DateTempl := '%'+DateTempl+'s';
  176.  Str(Length(TimeFormat),TimeTempl); TimeTempl := '%'+TimeTempl+'s';
  177.  
  178.  Assign(Output,''); Rewrite(Output);
  179.  Redirected := TestIfRedirected; DirectVideo := NOT Redirected;
  180.  
  181.  IF Redirected THEN
  182.   BEGIN
  183.    MaxViewLength := 255; DescTempl := '%-s';
  184.    Assign(Output,''); Rewrite(Output);
  185.  
  186.    DoPage := FALSE;
  187.   END
  188.  ELSE
  189.   BEGIN
  190.    AssignCrt(Output); Rewrite(Output);
  191.  
  192.    MaxViewLength := Lo(WindMax)-33-Length(DateFormat)-Length(TimeFormat);
  193.    Str(MaxViewLength,DescTempl); DescTempl := '%-'+DescTempl+'s';
  194.    ScreenHeight := Hi(WindMax);
  195.  
  196.    InitMemory;
  197.  
  198.    INIStrings := New(PINIStrings,Init); (* Read in the .INI file(s) *)
  199.    StringDateHandling.EvaluateINIFileSettings;
  200.    DescriptionHandling.EvaluateINIFileSettings;
  201.  
  202.    HilightMore := (ReadSettingsChar('4ff','hilightmore','y') = 'y');
  203.    DoPage      := (ReadSettingsChar('4ff','dopage','n') = 'y');
  204.  
  205.    Dispose(INIStrings,Done); INIStrings := NIL;
  206.   END;
  207. END.
  208.